import Vue from "vue"
import VueX from "vuex"

Vue.use(VueX)

const store = new VueX.Store({
    state: {
        user: {
            username: sessionStorage.getItem("username") || "visitor",
            realname: sessionStorage.getItem("realname") || "游客"
        }
    },
    mutations: {
        setUser(state, res) {
            state.user = res
            sessionStorage.setItem('username',res.username)
            sessionStorage.setItem('realname',res.realname)
        }
    }
})
export default store;